import { MES_imesApi } from '@/utils/Interceptors'

// 工单流程数据接口
export interface WorkOrderProcess {
  id: string
  workOrderId: string
  processName: string
  status: string
  startTime?: string
  endTime?: string
  employeeId?: string
  employeeName?: string
}

// 工单数据接口
export interface WorkOrder {
  id: string
  orderNumber: string
  productName: string
  quantity: number
  status: string
  createTime: string
  employeeId?: string
  employeeName?: string
}

// 获取工单流程数据
export const getWorkOrderProcesses = async (): Promise<WorkOrderProcess[]> => {
  try {
    const response = await MES_imesApi.get('/api/Customer/workorderprocesses')
    return response.data
  } catch (error) {
    console.error('获取工单流程数据失败:', error)
    throw error
  }
}

// 获取产品员工数据（工单列表）
export const getWorkOrders = async (): Promise<WorkOrder[]> => {
  try {
    const response = await MES_imesApi.get('/api/Customer/workorders')
    return response.data
  } catch (error) {
    console.error('获取工单数据失败:', error)
    throw error
  }
}

// 根据ID获取特定工单
export const getWorkOrderById = async (id: string): Promise<WorkOrder> => {
  try {
    const response = await MES_imesApi.get(`/api/Customer/workorders/${id}`)
    return response.data
  } catch (error) {
    console.error('获取工单详情失败:', error)
    throw error
  }
}

// 根据工单ID获取流程列表
export const getProcessesByWorkOrderId = async (workOrderId: string): Promise<WorkOrderProcess[]> => {
  try {
    const response = await MES_imesApi.get(`/api/Customer/workorderprocesses?workOrderId=${workOrderId}`)
    return response.data
  } catch (error) {
    console.error('获取工单流程失败:', error)
    throw error
  }
}
